From 2aa136a19c754ce2a38dcfb2a11b998f3f09c919 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 12 Apr 2020 23:45:03 -0400 Subject: [PATCH] Add a GtkFileChooserButton:modal property Nowadays, dialogs are expected to be attached, typically, and that only happens when they are marked as modal. --- docs/reference/gtk/gtk4-sections.txt | 2 ++ gtk/gtkfilechooserbutton.c | 43 ++++++++++++++++++++++++++-- gtk/gtkfilechooserbutton.h | 5 ++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 7638136709..e1bd5d9e32 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -1155,6 +1155,8 @@ gtk_file_chooser_button_get_title gtk_file_chooser_button_set_title gtk_file_chooser_button_get_width_chars gtk_file_chooser_button_set_width_chars +gtk_file_chooser_button_get_modal +gtk_file_chooser_button_set_modal GTK_FILE_CHOOSER_BUTTON diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index e0064fc9f3..92d5495570 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -127,7 +127,8 @@ enum PROP_DIALOG, PROP_TITLE, - PROP_WIDTH_CHARS + PROP_WIDTH_CHARS, + PROP_MODAL }; /* Signals */ @@ -535,6 +536,13 @@ gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class) -1, G_MAXINT, -1, GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_MODAL, + g_param_spec_boolean ("modal", + P_("Modal"), + P_("Whether to make the dialog modal"), + FALSE, + GTK_PARAM_READWRITE)); + _gtk_file_chooser_install_properties (gobject_class); gtk_widget_class_set_css_name (widget_class, I_("filechooserbutton")); @@ -1014,6 +1022,7 @@ gtk_file_chooser_button_set_property (GObject *object, break; case PROP_TITLE: + case PROP_MODAL: case GTK_FILE_CHOOSER_PROP_FILTER: case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value); @@ -1046,6 +1055,7 @@ gtk_file_chooser_button_get_property (GObject *object, break; case PROP_TITLE: + case PROP_MODAL: case GTK_FILE_CHOOSER_PROP_ACTION: case GTK_FILE_CHOOSER_PROP_FILTER: case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: @@ -2443,12 +2453,15 @@ open_dialog (GtkFileChooserButton *button) { if (GTK_IS_WINDOW (toplevel)) { + gboolean modal; + if (GTK_WINDOW (toplevel) != gtk_window_get_transient_for (GTK_WINDOW (priv->dialog))) gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), GTK_WINDOW (toplevel)); + g_object_get (priv->dialog, "modal", &modal, NULL); gtk_window_set_modal (GTK_WINDOW (priv->dialog), - gtk_window_get_modal (GTK_WINDOW (toplevel))); + modal | gtk_window_get_modal (GTK_WINDOW (toplevel))); } } } @@ -2458,12 +2471,15 @@ open_dialog (GtkFileChooserButton *button) { if (GTK_IS_WINDOW (toplevel)) { + gboolean modal; + if (GTK_WINDOW (toplevel) != gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (priv->native))) gtk_native_dialog_set_transient_for (GTK_NATIVE_DIALOG (priv->native), GTK_WINDOW (toplevel)); + g_object_get (priv->native, "modal", &modal, NULL); gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (priv->native), - gtk_window_get_modal (GTK_WINDOW (toplevel))); + modal | gtk_window_get_modal (GTK_WINDOW (toplevel))); } } } @@ -2753,3 +2769,24 @@ gtk_file_chooser_button_set_width_chars (GtkFileChooserButton *button, gtk_label_set_width_chars (GTK_LABEL (priv->label), n_chars); g_object_notify (G_OBJECT (button), "width-chars"); } + +void +gtk_file_chooser_button_set_modal (GtkFileChooserButton *button, + gboolean modal) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button)); + + g_object_set (button, "modal", modal, NULL); +} + +gboolean +gtk_file_chooser_button_get_modal (GtkFileChooserButton *button) +{ + gboolean modal; + + g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), FALSE); + + g_object_get (button, "modal", &modal, NULL); + + return modal; +} diff --git a/gtk/gtkfilechooserbutton.h b/gtk/gtkfilechooserbutton.h index 0d41d41f74..b17ca5956a 100644 --- a/gtk/gtkfilechooserbutton.h +++ b/gtk/gtkfilechooserbutton.h @@ -51,6 +51,11 @@ gint gtk_file_chooser_button_get_width_chars (GtkFileChooserBu GDK_AVAILABLE_IN_ALL void gtk_file_chooser_button_set_width_chars (GtkFileChooserButton *button, gint n_chars); +GDK_AVAILABLE_IN_ALL +gboolean gtk_file_chooser_button_get_modal (GtkFileChooserButton *button); +GDK_AVAILABLE_IN_ALL +void gtk_file_chooser_button_set_modal (GtkFileChooserButton *button, + gboolean modal); G_END_DECLS -- 2.30.2